use Dogtanian;
use Dogtanian::DB;
use Rose::DB::Object::Loader;

use strict;
use warnings;

my $loader = Rose::DB::Object::Loader->new(
	db => Dogtanian::DB->new,
	class_prefix => 'Dogtanian::Models'
);

#$loader->make_classes;

match qr/.*/ => sub {
	my ($nick, $text) = @_;

	my $line = Dogtanian::Models::Line->new(
		nick => $nick,
		content => $text,
		time => scalar(localtime)
	);

	$line->save();
};

command seen => sub {
	my $requested_nick = shift;
	print $requested_nick, "\n";

	my $lines = Dogtanian::Models::Line::Manager->get_lines(
		query => [
			nick => $requested_nick,
		],
		sort_by => 'time DESC',
		limit => 1
	);

	if (not @$lines) {
		say "Sorry, haven't seen $requested_nick!";
	} else {
		my $last_line = $lines->[0];
		say "$requested_nick last spoke at: $last_line->{time}, saying: \"$last_line->{content}\"";
	}
};
